package com.hospital.service.impl;

import com.hospital.dao.EqupayDao;
import com.hospital.dto.EquPayDto;
import com.hospital.entity.Equpay;
import com.hospital.service.intf.EqupayService;
import com.hospital.vo.PageBean;
import com.hospital.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EqupayServiceImpl implements EqupayService {
    @Autowired
    private EqupayDao dao;
    @Override
    public R add(Equpay equpay) {
        if (dao.add(equpay)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R deleById(int id) {
        if (dao.deleById(id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public PageBean selePage(int page, int limit) {
        int start=(page-1)*limit;

        long count = dao.selectCount();
        List<Equpay> list = dao.selectPage(start,limit);

        return PageBean.ok(count,list);
    }

    //批量删除
    @Override
    public R deleids(int[] ids) {
        if (dao.deleids(ids)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    //查询所有的设备消费记录
    @Override
    public PageBean querylog(int page, int limit) {
        int start=(page-1)*limit;

        long count = dao.equPayCount();
        List<EquPayDto> list = dao.equPay(start,limit);

        return PageBean.ok(count,list);
    }

    @Override
    public R save(EquPayDto equPayDto) {
        if (dao.save(equPayDto)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }
}
